package com.hejing.bpeldesign.bpelprase;

import com.hejing.bpeldesign.model.CaseNode;
import com.hejing.bpeldesign.model.BpelNode;
import org.w3c.dom.Element;

import java.util.UUID;

public class CaseNodeParser implements NodeParserStrategy {
    @Override
    public BpelNode parse(Element el) {
        String id = UUID.randomUUID().toString();
        String name = el.getAttribute("name");
        String bounds = el.getAttribute("bounds");

        String[] parts = bounds.split(",");
        int x = Integer.parseInt(parts[0]);
        int y = Integer.parseInt(parts[1]);
        int width = Integer.parseInt(parts[2]);
        int height = Integer.parseInt(parts[3]);

        String condition = el.getAttribute("condition");

        CaseNode node = new CaseNode(id, name, el.getTagName(), x, y, width, height);
        node.setCondition(condition);

        return node;
    }
}
